//
//  LGMInePersonalCenterViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/10.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGMInePersonalCenterViewController.h"
#import "LGForumDetailTableViewCell.h"
#import "LGForumReplayDetailViewController.h"
@interface LGMInePersonalCenterViewController ()
@property(nonatomic, strong) UILabel                     *attentionLable;
@property(nonatomic, strong) UILabel                     *commentLable;
@property(nonatomic, strong) UILabel                     *fansLable;
@end

@implementation LGMInePersonalCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人主页";
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = self.tableView.backgroundColor;
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(15, 10, 60, 60)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:30
                                            backgroundColor:nil
                                            backgroundImage:[UIImage imageNamed:@"1"]
                                                      image:nil];
    iconButton.centerX = UIScreenWidth / 2;
    [header addSubview:iconButton];
    
    STLabel * nameLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 10, iconButton.bottom + 10, UIScreenWidth, 20)
                                                    text:@"名字"
                                               textColor:FirstTextColor
                                                    font:16
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    [header addSubview:nameLable];
    nameLable.centerX = UIScreenWidth / 2;
    
    STButton * qiandaoButton = [[STButton alloc] initWithFrame:CGRectMake(0, nameLable.bottom  +20, 100, 25)
                                                         title:@"设置个人信息"
                                                    titleColor:FlatWhite
                                                     titleFont:14
                                                  cornerRadius:4
                                               backgroundColor:RGB(0xBCBCBC)
                                               backgroundImage:nil
                                                         image:nil];
    qiandaoButton.centerX = UIScreenWidth / 2;
    qiandaoButton.userInteractionEnabled = YES;
    [qiandaoButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedSettingButton];
    }];
    qiandaoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:qiandaoButton];
    
    self.attentionLable = [UILabel new];
    self.commentLable = [UILabel new];
    self.fansLable = [UILabel new];
    
    UIView * commentView = [self menuViewWithTitle:@"评论" lable:self.commentLable showRightLine:YES];
    commentView.top = qiandaoButton.bottom + 20;
    commentView.centerX = UIScreenWidth / 2;
    [header addSubview:commentView];
    
    UIView * attView = [self menuViewWithTitle:@"关注" lable:self.attentionLable showRightLine:YES];
    attView.top = qiandaoButton.bottom + 20;
    attView.right = commentView.left - 20;
    [header addSubview:attView];
    
    UIView * fensView = [self menuViewWithTitle:@"粉丝" lable:self.fansLable showRightLine:YES];
    fensView.top = qiandaoButton.bottom + 20;
    fensView.left = commentView.right + 20;
    [header addSubview:fensView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, fensView.bottom + 20, UIScreenWidth, 50)
                                                     text:@"         我的帖子(123)"
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:titleLable];
    titleLable.backgroundColor = [UIColor whiteColor];
    header.height = titleLable.bottom;
    
    self.tableView.tableHeaderView = header;
    
}
- (UIView*)menuViewWithTitle:(NSString*)title lable:(UILabel*)lable showRightLine:(BOOL)showRightLine{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    view.backgroundColor = [UIColor clearColor];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, view.width, 25)
                                                     text:title
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [view addSubview:titleLable];
    lable.frame = CGRectMake(0, 25, view.width, 25);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.textColor = FirstTextColor;
    lable.text = @"108";
    lable.font = [UIFont systemFontOfSize:14];
    [view addSubview:lable];

    [view st_showRightLine:40];
    return view;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGForumDetailTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGForumDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGForumDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    __weak typeof(self) weakSelf =  self;
    [cell.peopleButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedMoreReplayButtonWithIndexPath:indexPath];
    }];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)onSelctedSettingButton{
    
}
- (void)onSelctedMoreReplayButtonWithIndexPath:(NSIndexPath*)indexPath{
    [self.navigationController pushViewController:[LGForumReplayDetailViewController new] animated:YES];
}
@end
